﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Core;
namespace MvcWebUI.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Index(NguoiDung entity)
        {
            var nguoiDung = NguoiDung.Login(entity.TenDangNhap, entity.MatKhau);
            if (nguoiDung != null)
            {
                Session["Login"] = nguoiDung;
                return RedirectToAction("Index", "MainPage");
            }
            else
            {
                Session["Login"] = null;
                ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
            }
            return View(entity);
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
